//
//  JSKitManager+View.m
//  NiubilityProject
//
//  Created by Apple on 2018/5/14.
//  Copyright © 2018年 Apple. All rights reserved.
//

#import "JSKitManager+View.h"

@implementation JSKitManager (View)


-(UIView *)weakView{
    if (self.main && [self.main isKindOfClass:[UIView class]]) {
        return (UIView *)self.main;
    }
    return nil;
}
-(js_integer)view_tag{
    __weak typeof(self) weakSelf = self;
    return ^JSKitManager *(NSInteger tag){
        [weakSelf weakView].tag = tag;
        return weakSelf;
    };
}
-(js_color)view_tintColor{
    __weak typeof(self) weakSelf = self;
    return ^JSKitManager *(UIColor *tint){
        [weakSelf weakView].tintColor = tint;
        return weakSelf;
    };
}
-(js_color)view_backColor{
    __weak typeof(self) weakSelf = self;
    return ^JSKitManager *(UIColor *backColor){
        [weakSelf weakView].backgroundColor = backColor;
        return weakSelf;
    };
}
-(js_bool)view_userInteractionEnabled{
    __weak typeof(self) weakSelf = self;
    return ^JSKitManager *(BOOL interaction){
        [weakSelf weakView].userInteractionEnabled = interaction;
        return weakSelf;
    };
}
-(js_float)view_radius{
    __weak typeof(self) weakSelf = self;
    return ^JSKitManager *(CGFloat radius){
        UIView *tempv = [weakSelf weakView];
        tempv.layer.cornerRadius = radius;
        tempv.layer.masksToBounds= YES;
        return weakSelf;
    };
}
-(js_shadow)view_shadow{
    __weak typeof(self) weakSelf = self;
    return ^JSKitManager *(CGSize offset, CGFloat opacity, CGFloat radius){
        UIView *tempv = [weakSelf weakView];
        tempv.layer.shadowOffset = offset;
        tempv.layer.shadowOpacity = opacity;
        tempv.layer.shadowRadius = radius;
        return weakSelf;
    };
}
-(js_border)view_border{
    __weak typeof (self) weakSelf = self;
    return ^JSKitManager *(UIColor *borderColor, CGFloat borderWidth, CGFloat radius){
        UIView *tempv = [weakSelf weakView];
        tempv.layer.borderWidth = borderWidth;
        tempv.layer.backgroundColor = borderColor.CGColor;
        if (radius) {
            tempv.layer.cornerRadius = radius;
            tempv.layer.masksToBounds = YES;
        }
        
        return weakSelf;
    };
}
-(js_contentMode)view_contenModel{
    __weak typeof(self) weakSelf = self;
    return ^JSKitManager *(UIViewContentMode model){
        if (!weakSelf.js_UIlabel && !weakSelf.js_YYlabel) {
            [weakSelf weakView].contentMode = model;
        }
        return weakSelf;
    };
}
-(js_rect)view_frame{
    __weak typeof(self) weakSelf = self;
    return ^JSKitManager *(CGFloat x, CGFloat y, CGFloat w, CGFloat h){
        [weakSelf weakView].frame = CGRectMake(x, y, w, h);
        return weakSelf;
    };
}
-(js_point)view_center{
    __weak typeof(self) weakSelf = self;
    return ^JSKitManager *(CGPoint center){
        [weakSelf weakView].center = center;
        return weakSelf;
    };
}
-(js_size)view_size{
    __weak typeof(self) weakSelf = self;
    return ^JSKitManager *(CGSize size){
        [weakSelf weakView].size = size;
        return weakSelf;
    };
}
-(js_float)view_w{
    __weak typeof(self) weakSelf = self;
    return ^JSKitManager *(CGFloat w){
        CGRect oldFrmae = [weakSelf weakView].frame;
        [weakSelf weakView].frame = CGRectMake(oldFrmae.origin.x, oldFrmae.origin.y, w, oldFrmae.size.height);
        return weakSelf;
    };
}
-(js_float)view_h{
    __weak typeof(self) weakSelf = self;
    return ^JSKitManager *(CGFloat h){
        CGRect oldFrmae = [weakSelf weakView].frame;
        [weakSelf weakView].frame = CGRectMake(oldFrmae.origin.x, oldFrmae.origin.y, oldFrmae.size.width, h);
        return weakSelf;
    };
}
-(js_float)view_x{
    __weak typeof(self) weakSelf = self;
    return ^JSKitManager *(CGFloat x){
        CGRect oldFrmae = [weakSelf weakView].frame;
        [weakSelf weakView].frame = CGRectMake(x, oldFrmae.origin.y, oldFrmae.size.width, oldFrmae.size.height);
        return weakSelf;
    };
}
-(js_float)view_y{
    __weak typeof(self) weakSelf = self;
    return ^JSKitManager *(CGFloat y){
        CGRect oldFrmae = [weakSelf weakView].frame;
        [weakSelf weakView].frame = CGRectMake(oldFrmae.origin.x, y, oldFrmae.size.width, oldFrmae.size.height);
        return weakSelf;
    };
}
-(js_bool)view_clipsToBounds{
    __weak typeof(self) weakSelf = self;
    return ^JSKitManager *(BOOL clips){
        [weakSelf weakView].clipsToBounds = clips;
        return weakSelf;
    };
}
-(js_float)view_alpha{
    __weak typeof(self) weakSelf = self;
    return ^JSKitManager *(CGFloat alpha){
        [weakSelf weakView].alpha = alpha;
        return weakSelf;
    };
}
-(js_bool)view_opaque{
    __weak typeof(self) weakSelf = self;
    return ^JSKitManager *(BOOL opaque){
        [weakSelf weakView].opaque = opaque;
        return weakSelf;
    };
    
}
-(js_bool)view_hiden{
    __weak typeof(self) weakSelf = self;
    return ^JSKitManager *(BOOL hiden){
        [weakSelf weakView].hidden = hiden;
        return weakSelf;
    };
}
@end
